package com.lugea.common.json;

import java.io.IOException;

import org.joda.time.DateTime;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;

/**
 * @author enluw
 * @date 2020-01-27
 * @描述
 */
public class DateTimeStdScalarDeserializer extends StdScalarDeserializer<DateTime> {
    private static final long serialVersionUID = -2711832162430606759L;

    protected DateTimeStdScalarDeserializer() {
        super(DateTime.class);
    }

    @Override
    public DateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
            throws IOException, JsonProcessingException {
        JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
        return DateTime.parse(jsonNode.asText());
    }
}
